//
// Created by ZYZ on 2020/6/12.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "test_memory.h"
#include "../../include/type_poly.h"

//测试 free 指针所指向的内存后，该指针指向的内存的数据是否存在
void test_free_memory() {
    Link p = (Link) malloc(sizeof(LNode)); // 生成头结点
    p->data.expn = 3;
    p->data.coef = 5;
    p->next = NULL;
    free(p);
    printf("%f", p->data.coef);
}

//测试 free() 一个对象的地址是否报错
void test_free_memory2(){
    ElemType elemType;
    elemType.coef = 3;
    elemType.expn = 5;
    free(&elemType);
// malloc: *** error for object 0x7ffeefbcf768: pointer being freed was not allocated
// 地址为 0x7ffeefbcf768 的指针没有申请内存但是正在被释放
// malloc: *** set a breakpoint in malloc_error_break to debug
}

void test_memset(){
    char a[100] = "dfdfdgrett" ;
    memset(a,0,sizeof(a)/sizeof(char));
    printf("memset 后字符串为: %s",a);
}